package com.rural.bus.driver.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.rural.bus.driver.R;
import com.rural.bus.driver.model.Order;
import com.rural.bus.driver.utils.DateUtil;

/**
 * 订单取消对话框
 * 
 * @author Peanut
 */
public class OrderCancelDialog extends Dialog implements View.OnClickListener {
	private TextView tv_start_time, tv_start_location, tv_end_location, tv_passenger_name;
	private Button btn_confirm;
	
	private Order order;
	private OnDialogButtonListener onDialogButtonListener;

	public interface OnDialogButtonListener {
		void onConfirmClicked();
	}

	public OrderCancelDialog(Context context, Order order, OnDialogButtonListener listner) {
		super(context, R.style.common_alert_dialog);
		this.onDialogButtonListener = listner;
		this.order = order;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.view_order_cancel_dialog);
		initView();
	}

	private void initView() {
		tv_start_time = (TextView) findViewById(R.id.tv_start_time);
		tv_start_location = (TextView) findViewById(R.id.tv_start_location);
		tv_end_location = (TextView) findViewById(R.id.tv_end_location);
		tv_passenger_name = (TextView) findViewById(R.id.tv_passenger_name);
		btn_confirm = (Button) findViewById(R.id.btn_confirm);
		btn_confirm.setOnClickListener(this);

		tv_start_time.setText("" + DateUtil.formatDiscriptionTime(order.takeTime));
		tv_start_location.setText("" + order.startLocation);
		tv_end_location.setText("" + order.endLocation);
		tv_passenger_name.setText("" + order.userName);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_confirm:
			if (onDialogButtonListener != null) {
				dismiss();
				onDialogButtonListener.onConfirmClicked();
			}
			break;
		default:
			break;
		}
	}

}
